package com.miya.demo.support.rabbitmq.delay;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * 延迟demo配置
 *
 * @author Caixiaowei
 * @date 2022/08/08
 */
@Configuration
public class DelayDemoConfig {

    /**
     * 微信支付延迟查询交换机
     */
    public static final String DELAY_EXCHANGE = "delay_exchange";

    /**
     * 微信支付延迟查询队列
     */
    public static final String DELAY_QUEUE = "delay_queue";

    /**
     * 微信支付延迟查询路由key
     */
    public static final String DELAY_ROUTINGKEY = "delay_routingkey";


    @Bean(name = "delayExchange")
    public CustomExchange delayExchange(){
        Map<String, Object> args = new HashMap<>(4);
        args.put("x-delayed-type","direct");
        CustomExchange exchange = new CustomExchange(DELAY_EXCHANGE,"x-delayed-message", true, false,args);
        return exchange;
    }

    @Bean(name = "delayQueue")
    public Queue delayQueue(){
        return new Queue(DELAY_QUEUE, true);
    }

    @Bean
    public Binding wechatPayQueryBinding(){
        return BindingBuilder
                .bind(delayQueue())
                .to(delayExchange())
                .with(DELAY_ROUTINGKEY)
                .noargs();
    }
}
